﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace VNet.VisiSuite.Common.Converters
{
    public class ColorStringToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // safe code to prevent the invalid data
            if (value == null)  
            {
                value = "#222223";   
            }
            string input = value.ToString();

            if (!input.StartsWith("#"))
                input = "#" + input;

            return input;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}